package io.renren.modules.news.service.impl;

import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.modules.news.dao.V9NewsDao;
import io.renren.modules.news.entity.V9NewsEntity;
import io.renren.modules.news.service.V9NewsService;
import io.renren.modules.news_data.service.V9NewsDataService;

@Service("v9NewsService")
public class V9NewsServiceImpl extends ServiceImpl<V9NewsDao, V9NewsEntity> implements V9NewsService {

	@Autowired
	private V9NewsDataService v9NewsDataService;

	@Override
	public PageUtils queryPage(Map<String, Object> params) {
		IPage<V9NewsEntity> page = this.page(new Query<V9NewsEntity>().getPage(params),
				new QueryWrapper<V9NewsEntity>());
		// List<V9NewsEntity> records = page.getRecords();
		// for (V9NewsEntity v9NewsEntity : records) {
		// Integer newsid=v9NewsEntity.getId();
		// List<V9NewsDataEntity> list = v9NewsDataService.list(new
		// QueryWrapper<V9NewsDataEntity>().eq("id", newsid));
		// v9NewsEntity.setDataEntity(list.get(0));
		// }
		return new PageUtils(page);
	}

	@Override
	public PageUtils getNewsList(Map<String, Object> params) {
		String cateid=(String) params.get("cateid");
		Integer catid=0;
		if (StringUtils.isNotBlank(cateid)) {
			catid=Integer.parseInt(cateid);
		}
		IPage<V9NewsEntity> page = this.page(new Query<V9NewsEntity>().getPage(params, "id", false),
				new QueryWrapper<V9NewsEntity>()
				.eq(catid!=0, "catid", catid)
				);
		return new PageUtils(page);

	}

}